package service_blog_mirchen_com

import (
	"gen-go/BlogServices"
	"github.com/jinzhu/gorm"
)

//service结构
type ConfigServiceHandler struct {
	orm *gorm.DB
}

//Admin
type Admin struct {
	Id              int64  `gorm:"primary_key"`
	Username        string
	Password        string
	Email           string
	QQ              string
	Tel             string
	Avatar          string
	SiteName        string
	SiteKeywords    string
	SiteDescription string
	SiteAuthor      string
	SiteSign        string
	SiteIcp         string
}

func NewConfigServiceHandler(getOrm *gorm.DB) *ConfigServiceHandler {
	return &ConfigServiceHandler{orm:getOrm}
}

func (ats *ConfigServiceHandler) GetConfig() (*BlogServices.Config, error) {
	admin := Admin{}
	err := ats.orm.First(&admin).Error
	if err != nil {
		return &BlogServices.Config{}, nil
	} else {
		return &BlogServices.Config{
			Email      	: admin.Email,
			QQ         	: admin.QQ,
			Tel        	: admin.Tel,
			Avatar     	: admin.Avatar,
			SiteName   	: admin.SiteName,
			SiteKeywords  	: admin.SiteKeywords,
			SiteDescription : admin.SiteDescription,
			SiteAuthor      : admin.SiteAuthor,
			SiteSign       	: admin.SiteSign,
			SiteIcp        	: admin.SiteIcp,
		}, nil
	}

}
